Skip to content

fix(decopilot): prevent Cloudflare 524 timeout on stream endpoint#2509

Merged
JonasJesus42 merged 1 commit intomainfrom
fix/decopilot-cloudflare-524-timeout
Feb 27, 2026
Merged

fix(decopilot): prevent Cloudflare 524 timeout on stream endpoint#2509
JonasJesus42 merged 1 commit intomainfrom
fix/decopilot-cloudflare-524-timeout

Conversation

@JonasJesus42
Copy link
Contributor

@JonasJesus42 JonasJesus42 commented Feb 27, 2026

Move MCP client creation (clientFromConnection, createVirtualClientFrom, createModelProviderFromClient) from the synchronous request handler into the stream execute callback. This ensures the SSE response headers are flushed to the client immediately, before the potentially slow MCP connection setup begins.

Previously, the handler awaited all MCP client connections before returning createUIMessageStreamResponse, causing Cloudflare to timeout (524) when client initialization exceeded 100 seconds.

Agent-specific system instructions are now lazily enriched inside execute once the passthrough client is available, identified by the stable message id decopilot-system.

Made-with: Cursor

What is this contribution about?

Describe your changes and why they're needed.

Screenshots/Demonstration

Add screenshots or a Loom video if your changes affect the UI.

How to Test

Provide step-by-step instructions for reviewers to test your changes:

  1. Step one
  2. Step two
  3. Expected outcome

Migration Notes

If this PR requires database migrations, configuration changes, or other setup steps, document them here. Remove this section if not applicable.

Review Checklist

  • PR title is clear and descriptive
  • Changes are tested and working
  • Documentation is updated (if needed)
  • No breaking changes

Summary by cubic

Prevents Cloudflare 524 timeouts on the Decopilot stream endpoint by moving MCP client setup into the SSE execute callback so headers flush immediately. Agent instructions are now injected lazily once the passthrough client is ready.

  • Bug Fixes
    • Initialize model, passthrough, and strategy MCP clients inside execute to avoid blocking the response.
    • Preload a base system prompt and enrich it later via the decopilot-system message with agent instructions.
    • Keep tool wiring intact; gateway modes expose only strategy + built-in tools to the model.
    • Abort handling closes clients and fails the thread to prevent leaks.

Written for commit c84fcf2. Summary will update on new commits.

Move MCP client creation (clientFromConnection, createVirtualClientFrom,
createModelProviderFromClient) from the synchronous request handler into
the stream execute callback. This ensures the SSE response headers are
flushed to the client immediately, before the potentially slow MCP
connection setup begins.

Previously, the handler awaited all MCP client connections before
returning createUIMessageStreamResponse, causing Cloudflare to timeout
(524) when client initialization exceeded 100 seconds.

Agent-specific system instructions are now lazily enriched inside
execute once the passthrough client is available, identified by
the stable message id decopilot-system.

Made-with: Cursor
@github-actions
Copy link
Contributor

🧪 Benchmark

Should we run the Virtual MCP strategy benchmark for this PR?

React with 👍 to run the benchmark.

Reaction Action
👍 Run quick benchmark (10 & 128 tools)

Benchmark will run on the next push after you react.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2026

Release Options

Should a new version be published when this PR is merged?

React with an emoji to vote on the release type:

Reaction Type Next Version
👍 Prerelease 2.120.1-alpha.1
🎉 Patch 2.120.1
❤️ Minor 2.121.0
🚀 Major 3.0.0

Current version: 2.120.0

Deployment

  • Deploy to production (triggers ArgoCD sync after Docker image is published)

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

@JonasJesus42 JonasJesus42 merged commit fa89db4 into main Feb 27, 2026
8 checks passed
@JonasJesus42 JonasJesus42 deleted the fix/decopilot-cloudflare-524-timeout branch February 27, 2026 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant